package de.fzi.kasma.learner.function.scoring;

import de.fzi.kasma.learner.data.Data;
import de.fzi.kasma.learner.data.Dataset;
import de.fzi.kasma.learner.function.prediction.PredictionFunction;

public class SVMScoringFunction extends ScoringFunction{

	public SVMScoringFunction(PredictionFunction f, Dataset d) {
		super(f, d);
	}

	@Override
	public double getScore() {

          double score = 0;
          try {
			score = getAccuracy() -predFnc.getComplexity();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return score;
	}
	
	public double getAccuracy() throws Exception{
		
		int correct = 0;
		int total = 0;
		
		for(Data d : ds.getAllData()){
			
	     	double prediction = predFnc.getPrediction(d).getValue();
		    if(prediction == d.getLabel().getValue())
		    	++correct;
		    ++total;
		}
		
	
//		System.out.print("Accuracy = "+(double)correct/total*100+
//				 "% ("+correct+"/"+total+") (classification)\n");
		
		return (double)correct/total*100;
		
	}

}
